package com.lagou.service.impl;

import com.lagou.entity.AuthCode;
import com.lagou.service.api.CodeService;
import com.lagou.service.biz.CodeBizService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private CodeBizService codeBizService;

    @Override
    public int validateCode(String email, String code) {
        AuthCode authCode = codeBizService.getCode(code);
        if (authCode == null || !authCode.getEmail().equals(email)) {
            return 1;
        } else if (authCode.getExpireTime().before(new Date())) {
            return 2;
        }
        return 0;
    }

}
